package lab03.test08;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        String file1="";
        String file2="";
        String file3="";
        //字节流读文件
        FileInputStream file1InputStream=null;
        FileInputStream file2InputStream=null;
        FileInputStream file3InputStream=null;
        //字节流写文件
        FileOutputStream file3OutputStream=null;
        try {
            file1InputStream = new FileInputStream(file1);
            file2InputStream = new FileInputStream(file2);
            file3InputStream = new FileInputStream(file3);

            //一次读一个字节
            int data1=0;
            int data2=0;
            while (
                    ((data1=file1InputStream.read()) !=-1)

                            ||((data2=file2InputStream.read()) != -1)

                    ){

                file3OutputStream.write(data1);
                file3OutputStream.write(data2);
                }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {

            try {
                file3OutputStream.close();
                file1InputStream.close();
                file2InputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
